package com.mcf.xiaolinju.service.impl;

import com.mcf.xiaolinju.entity.UserDetails;
import com.mcf.xiaolinju.mapper.UserDetailsMapper;
import com.mcf.xiaolinju.service.IUserDetailsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

@Service
public class UserDetailsServiceImpl extends ServiceImpl<UserDetailsMapper, UserDetails> implements IUserDetailsService {
@Resource
    UserDetailsMapper userDetailsMapper;
//通过userid输出用户详细信息表的内容
public UserDetails getmessage (Integer id){
    return  userDetailsMapper.getmessage(id);
}
//通过userid修改表的用户性别和电话号
    public String updateByUserid (int userid ,String phonenum,int updateid){
        Date date=new Date();
        LocalDateTime ldt=date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
    if(userDetailsMapper.updateByUserid(userid,phonenum,updateid,ldt)>0){
        return  "修改成功";
    }
    return "修改失败";
    }
    //通过userid查询出用户的身份证号
    public String  getCardId(int id){
      return userDetailsMapper.getCardId(id);
    }
    //通过用户名查询出用户的身份证号
    public String getIdNumber(String username){
    return  userDetailsMapper.getIdNumber(username);
    }
    //修改用户的头像
    public String updateportrait(String portraiturl, int userid ,int updateid) {
        Date date=new Date();
        LocalDateTime ldt=date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
             if(userDetailsMapper.updateportrait(portraiturl,userid,updateid,ldt)>0) {
                 return "修改成功";
             }
             return "修改失败";
    }

    public UserDetails selectdetailmessage(int userid) {
    return userDetailsMapper.selectdetailmessage(userid);

    }
}
